import {get,post} from '../../utils/request.js'
const state={
   //出来的栏目信息
    products:[],
    total:0
}

const actions={
  findAllProduct(context,list){
    get('/product/pageQuery',list).then(res =>{
      let response = res.data.list
      let total = res.data.total
      // console.log(response,total);
      context.commit('SET_PRODUCTS',response)
      context.commit('SET_TOTAL',total)
    })
  },
  //保存栏目信息
  saveProduct(context,list){
    console.log(post);
    let response = post('/product/saveOrUpdate',list)
    return response
  },
  deleteProduct(context,list){
    let response = get('/product/offline',list)
    return response
  }
}

const mutations={
  //修改state中的值
  SET_PRODUCTS(state,response){
    state.products = response
  },
  SET_TOTAL(state,total){
    state.total = total
  }
}

export default {
    namespaced:true,
    state,
    actions,
    mutations
  }